package org.awenlice.playerdailyshop.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.awenlice.playerdailyshop.config.ShopConfig;

import java.util.Objects;

import static org.awenlice.playerdailyshop.config.ShopConfig.*;

public class RandomItemGenerator {
    private static final Logger LOGGER = LogManager.getLogger(); // 添加日志

    public static ShopConfig.ShopItem getRandomItem(String model) {
        double random = Math.random();
        double target = 0.0;
        String quality = "0";
        for (ShopConfig.weightItem weight: weightItems){
            if (random <= target + weight.probability){
                quality = weight.name;
                break;
            }
        }
        if (Objects.equals(model, "Sell")){
            int t = (int)(Math.random()*sell.get(quality).size());
            if (t >= 0){
                return sell.get(quality).get(t);
            }else{
                LOGGER.warn("No item selected!"); // 日志输出
                return null;
            }
        }else{
            int t = (int)(Math.random()*buy.get(quality).size());
            if (t >= 0){
                ShopConfig.ShopItem r = buy.get(quality).get(t) ;
                return buy.get(quality).get(t);
            }else{
                LOGGER.warn("No item selected!"); // 日志输出
                return null;
            }

        }
    }
}